<template>
  <div style="width: 60%;margin: auto auto">
    <el-form :inline="true">
      <h2>用户基本信息填写</h2>
      <el-form-item label="手机号码" prop="symptom" :label-width="formLabelWidth">
        <el-input v-model="loginData.patient.tellphone" />
      </el-form-item>
      <el-form-item label="用户真实姓名" prop="symptom" :label-width="formLabelWidth">
        <el-input v-model="loginData.patient.realName" />
      </el-form-item>
      <el-form-item label="年龄" prop="symptom" :label-width="formLabelWidth">
        <el-input v-model="loginData.patient.age" />
      </el-form-item>
      <el-form-item label="联系人姓名" prop="symptom" :label-width="formLabelWidth">
        <el-input v-model="loginData.patient.relaName" />
      </el-form-item>
      <el-form-item label="联系人电话" prop="symptom" :label-width="formLabelWidth">
        <el-input v-model="loginData.patient.relaPhone" />
      </el-form-item>
      <el-form-item label="身份证号码" prop="identityNo" :label-width="formLabelWidth">
        <el-input v-model="loginData.patient.identityNo" />
      </el-form-item>
      <el-form-item label="性别" prop="symptom" :label-width="formLabelWidth">
        <el-radio v-model="loginData.patient.gender" label="0">女性</el-radio>
        <el-radio v-model="loginData.patient.gender" label="1">男性</el-radio>
      </el-form-item>

      <h2>病例填写</h2>
      <el-form-item label="疾病症状" prop="symptom" :label-width="formLabelWidth">
        <el-input v-model="loginData.record.symptom" type="textarea" />
      </el-form-item>
      <el-form-item label="医生诊断" prop="diagnosis" :label-width="formLabelWidth">
        <el-input v-model="loginData.record.diagnosis" type="textarea" />
      </el-form-item>
      <el-form-item label="过敏史" prop="allergy" :label-width="formLabelWidth">
        <el-input v-model="loginData.record.allergy" />
      </el-form-item>
      <el-form-item label="检查日期" prop="checkTime" :label-width="formLabelWidth">
        <template>
          <div class="block">
            <el-date-picker
              v-model="loginData.record.checkTime"
              type="date"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期"
            />
          </div>
        </template>
      </el-form-item>
      <el-form-item label="传染性" prop="isInfectious" :label-width="formLabelWidth">
        <template>
          <el-radio v-model="loginData.record.isInfectious" label="0">否</el-radio>
          <el-radio v-model="loginData.record.isInfectious" label="1">是</el-radio>
        </template>
      </el-form-item>
      <el-form-item label="是否复诊" prop="isRecheck" :label-width="formLabelWidth">
        <template>
          <el-radio v-model="loginData.record.isRecheck" label="0">否</el-radio>
          <el-radio v-model="loginData.record.isRecheck" label="1">是</el-radio>
        </template>
      </el-form-item>
      <h2>住院申请填写</h2>
      <el-col :span="12">
        <el-form-item label="入住时间" :label-width="formLabelWidth">
          <el-date-picker
            v-model="loginData.application.applyTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="date"
            placeholder="选择日期"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="科室" :label-width="formLabelWidth">
          <el-select v-model="loginData.application.depId" placeholder="请选择科室">
            <el-option v-for="item in depList" :key="item.id" :label="item.depName" :value="item.id" />
          </el-select>
        </el-form-item>
      </el-col>
      <el-form-item label="病房类型" :label-width="formLabelWidth">
        <el-select v-model="loginData.application.wardType" placeholder="请选择病房类型">
          <el-option label="普通病房" value="0" />
          <el-option label="高级病房" value="1" />
          <el-option label="特护病房" value="2" />
        </el-select>
      </el-form-item>
      <div style="width: 300px;margin: auto auto">
        <el-button type="primary" @click="submit">
          确认提交
        </el-button>
        <el-button type="danger" @click="reset">
          清空
        </el-button>
      </div>
    </el-form>
    <div style="height: 100px" />
  </div>
</template>

<script>
import {
  getAllFather
} from '@/api/department'
import {
  insertByTemp
} from '@/api/application/application'
export default {
  name: 'Apply',
  data() {
    return {
      formLabelWidth: '120px',
      loginData: {
        record: {
          symptom: '',
          diagnosis: '',
          allergy: '',
          isInfectious: '0',
          isRecheck: '0',
          checkTime: ''
        },
        application: {
          depId: '',
          wardType: '',
          applyTime: ''
        },
        patient: {
          tellphone: '',
          password: '11111',
          gender: '0',
          identityNo: '',
          relaName: '',
          relaPhone: '',
        }
      },
      temp2: {
        symptom: '',
        diagnosis: '',
        allergy: '',
        isInfectious: '0',
        isRecheck: '0',
        checkTime: ''
      },
      form2: {
        depId: '',
        wardType: '',
        applyTime: ''
      },
      patient2: {
        tellphone: '',
        password: '11111',
        gender: '0',
        identityNo: '',
        relaName: '',
        relaPhone: '',
      },
      depList: []
    }
  },
  created() {
    // 查询科室
    getAllFather().then(res => {
      this.depList = res.content
    })
  },
  methods: {
    submit() {
      insertByTemp(this.loginData).then(res => {
        this.$notify({
          title: '成功',
          message: '添加成功',
          type: 'success',
          duration: 2000
        })
        this.reset()
      })
    },
    reset() {
      console.log(1)
      this.loginData.record = this.temp2
      this.loginData.application = this.form2
      this.loginData.patient = this.patient2
    }

  }
}
</script>

<style>
</style>
